// ==UserScript==
// @name           Waze.su Forum
// @namespace      Waze.su-Forum
// @description    Change Waze.su Forum
// @include        http://waze.su/forum/*
// @match          http://waze.su/forum/*
// @updateURL      https://waze-yandexmap-extended-tools.googlecode.com/svn/trunk/waze.su-forum.user.js
// @downloadURL    https://waze-yandexmap-extended-tools.googlecode.com/svn/trunk/waze.su-forum.user.js
// @version        1.1.0
// @author         skirda
// @grant          unsafeWindow
// ==/UserScript==

(function ( window, undefined ) {
    var version = "1.1.0";
    /* from http://code.google.com/p/waze-papyrus-extended-tools */
    if(window.navigator.vendor.match(/Google/)) {
        unsafeWindow = (function() {
            var el = document.createElement('p');
            el.setAttribute('onclick', 'return window;');
            return el.onclick();
        })();
    };

    var $   = unsafeWindow.$;
    var doc = unsafeWindow.document;
    unsafeWindow.console.log("Waze.su Forum ("+version+"): Start");

    var onready = function() {
        var PageBodyID = doc.getElementsByClassName("icon-home");

        if (typeof PageBodyID != "undefined")
        {
            unsafeWindow.console.log("Waze.su Forum ("+version+"): found '" + PageBodyID + "'");
            var aitems = ["unreadposts", "Непрочитанные", "newposts", "Новые"];
            for (var i=0; i < aitems.length; i+=2)
                PageBodyID[0].innerHTML=PageBodyID[0].innerHTML+" • "+ "<a href='./search.php?search_id=" + aitems[i] + "'>" + aitems[i+1] + "</a>";
        }
        else
            unsafeWindow.console.log("Waze.su Forum ("+version+"): not found 'page-body'");
    };
    window.addEventListener("load", onready, false);

})(window);
